import cv2 as cv2

video_path = r"G:\Code\Ccode\项目\2024-9-29_少帅\2024-9-29_少帅\2.mp4"
cap = cv2.VideoCapture(video_path)

while True:
    ret, frame = cap.read()
    if not ret:
        break

    grep_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    x = cv2.Sobel(grep_frame, cv2.CV_64F, 1, 0, ksize=5)
    y = cv2.Sobel(grep_frame, cv2.CV_64F, 0, 1, ksize=5)
    combined = cv2.magnitude(x, y)

    output = cv2.convertScaleAbs(combined)
    output_resized = cv2.resize(output, (frame.shape[1] // 2, frame.shape[0] // 2))

    cv2.imshow('shaoshuai', output_resized)

    if cv2.getWindowProperty("shaoshuai", cv2.WND_PROP_VISIBLE) < 1:
        break

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
